package com.soo.hoo.admin.api;

import com.soo.hoo.admin.model.dto.FileDTO;
import com.soo.hoo.admin.model.dto.ImageFileDTO;
import com.soo.hoo.admin.model.entity.SysBookCover;
import com.soo.hoo.admin.model.entity.SysSuggestion;
import com.soo.hoo.admin.service.FileService;
import com.soo.hoo.admin.service.SuggestionService;
import com.soo.hoo.core.annotation.OperateLog;
import com.soo.hoo.core.enums.BusinessTypeEnum;
import com.soo.hoo.core.model.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 反馈管理
 * </p>
 *
 * @author 杨燚
 * @since 2024/5/15
 */
@Tag(name = "反馈管理")
@RequestMapping("/suggest/")
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SuggestionController {


    private final SuggestionService suggestionService;
    private final FileService fileService;


    @PostMapping("upload")
    @Operation(summary = "上传图片")
    @OperateLog(title = "上传图片", businessType = BusinessTypeEnum.UPLOAD)
    public Result<ImageFileDTO> upload(@RequestParam MultipartFile file) {
        ImageFileDTO upload = fileService.uploadImage(file, "suggestion");
        return Result.success(upload);
    }

    @PostMapping("create")
    @Operation(summary = "提交反馈")
    @OperateLog(title = "提交反馈", businessType = BusinessTypeEnum.CREATE)
    public Result<Void> create(@RequestBody @Valid SysSuggestion suggestion) {
        suggestion.setDone(false);
        suggestionService.save(suggestion);
        return Result.success();
    }

    @DeleteMapping("delPicture")
    @Operation(summary = "删除图片")
    @OperateLog(title = "删除图片", businessType = BusinessTypeEnum.DELETE)
    public Result<Void> delPicture(@RequestParam Long pictureId) {
        fileService.removeFile(pictureId);
        return Result.success();
    }
}
